package com.lakeworks.web.controller.core;

import com.lakeworks.common.annotation.RoleAnnotation;
import com.lakeworks.common.core.controller.BaseController;
import com.lakeworks.common.core.domain.AjaxResult;
import com.lakeworks.common.enums.UserRoleType;
import com.lakeworks.domain.SysProduct;
import com.lakeworks.service.ISysProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * 产品基本信息Controller
 *
 * @author lake
 * @date 2023-02-08
 */
@RestController
@RequestMapping("/system")
public class SysProductController extends BaseController {

    @Autowired
    private ISysProductService sysProductService;


    @Value("${lakeworks.app}")
    private String factoryCode;

    /**
     * 渠道产品列表
     */
    @GetMapping("/channel/{channelId}/products")
    public AjaxResult list(@PathVariable Long channelId) {
        return success(sysProductService.productListByChannelId(channelId));
    }

    @GetMapping("/product/{id}")
    public AjaxResult selectById(@PathVariable("id") Long id) {
        return success(sysProductService.selectSysProductById(id));
    }

    /**
     * 查询工厂代码
     */
    @GetMapping("/factory/code")
    public AjaxResult getFactoryCode() {
        return success(factoryCode);
    }

    /**
     * 查询排序系统产品列表
     */
    @GetMapping("/sort/products")
    @RoleAnnotation(UserRoleType.GLRY)
    public AjaxResult products(SysProduct sysProduct) {
        return success(sysProductService.selectSysProducts(sysProduct));
    }

    /**
     *修改排序
     * */
    @PatchMapping("/product/sort")
    @RoleAnnotation(UserRoleType.GLRY)
    public AjaxResult sort(@RequestBody SysProduct sysProduct){
        return success(sysProductService.updateSysProduct(sysProduct));
    }

}
